//
//  Constants.m
//  SkyworthPalmExam
//
//  Created by Arvin Wang on 15/1/19.
//  Copyright (c) 2015年 Arvin Wang. All rights reserved.
//

#import "Constants.h"
#import "UIImageView+WebCache.h"

@implementation Constants

+ (void)setStatusBarWhite:(UIViewController *)viewController{
    /*
    if (iOS7Later) {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    }else{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    }
     */
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}

+(void)hideTabBar:(UITabBarController *) tabbarcontroller{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x,kScreenHeight, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, kScreenHeight)];
        }
    }
    
    [UIView commitAnimations];
}

+(void)showTabBar:(UITabBarController *) tabbarcontroller{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        NSLog(@"%@", view);
        
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, kScreenHeight-49.0, view.frame.size.width, view.frame.size.height)];
            
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, kScreenHeight-49.0)];
        }
    }
    
    [UIView commitAnimations];
}

/**
 *  隐藏tableView中多余的cell
 *
 *  @param tableView UITableView
 */
+ (void)setExtraCellLineHidden:(UITableView *)tableView{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
}

/**
 *  修改设置中tableView的样色
 *
 *  @param tableView UITableView
 */
+ (void)setSettingTableViewStyle:(UITableView *)tableView{
    CGRect frame = tableView.bounds;
    frame.origin.y = -frame.size.height;
    UIView *boundsView = [[UIView alloc] initWithFrame:frame];
    CGFloat value = 242.0 / 255;
    boundsView.backgroundColor = [UIColor colorWithRed:value green:value blue:value alpha:1];
    [tableView addSubview:boundsView];
    if (!iOS7Later) {
        tableView.backgroundView = nil;
    }
}

/**
 *  显示远程图片
 *
 *  @param url   图片地址
 *  @param frame 图片frame
 *  @param view  父视图
 *
 *  @return UIImageView
 */
+ (UIImageView *)loadImageViewWithURL:(NSString *)url imageViewFrame:(CGRect)frame superView:(UIView *)view{
    UIImageView *imageView = [self loadImageViewWithURL:url imageViewFrame:frame superView:view contentMode:UIViewContentModeScaleAspectFill];
    return imageView;
}

+ (UIImageView *)loadImageViewWithURL:(NSString *)url imageViewFrame:(CGRect)frame superView:(UIView *)view contentMode:(UIViewContentMode)contentMode{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
    imageView.contentMode = contentMode;
    imageView.clipsToBounds = YES;
    
    [self setImageWithURL:url imageView:imageView];
    
    [view addSubview:imageView];
    return imageView;
}

+ (void)setImageWithURL:(NSString *)url imageView:(UIImageView *)imageView contentMode:(UIViewContentMode)contentMode{
    imageView.contentMode = contentMode;
    imageView.clipsToBounds = YES;
    
    [self setImageWithURL:url imageView:imageView];
}

+ (void)setImageWithURL:(NSString *)url imageView:(UIImageView *)imageView{
    [self setImageWithURL:url imageView:imageView placeholder:@"placeholder"];
}

+ (void)setImageWithURL:(NSString *)url imageView:(UIImageView *)imageView placeholder:(NSString *)placeholder{
    [self setImageWithURL:url imageView:imageView placeholder:placeholder autoSize:YES];
}

+ (void)setImageWithURL:(NSString *)url imageView:(UIImageView *)imageView placeholder:(NSString *)placeholder autoSize:(BOOL)autoSize{
//    NSString *imageURL;
    if (url && url.length > 0) {
        // 设置尺寸
        NSArray *sizeArray = @[@64, @128, @256, @512, @768, @1024];
        NSUInteger realWidth = (NSUInteger)CGRectGetWidth(imageView.frame) * 2;
        NSUInteger fitWidth = 0;
        for (NSNumber *number in sizeArray) {
            NSUInteger width = [number unsignedIntegerValue];
            if (width >= realWidth) {
                fitWidth = width;
                break;
            }
        }
        
//        NSString *fileName = [url stringByDeletingPathExtension];
//        NSString *fileExtension = [url pathExtension];
//        if (fitWidth == 0 || !autoSize) {
//            imageURL = [NSString stringWithFormat:@"%@%@.%@", kApiURL, fileName, fileExtension];
//        } else {
//            imageURL = [NSString stringWithFormat:@"%@%@_%lu.%@", kApiURL, fileName, (unsigned long)fitWidth, fileExtension];
//        }
    }
    [imageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:placeholder] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
}

+(NSString *)JSONString:(id)object{
    NSError* error = nil;
    id result = [NSJSONSerialization dataWithJSONObject:object
                                                options:kNilOptions error:&error];
    if (error != nil) return nil;
    
    NSString *jsonString = [[NSString alloc] initWithData:result
                                                 encoding:NSUTF8StringEncoding];
    return jsonString;
}

+ (void)callTelephoneWithPhone:(NSString *)phoneNum atViewController:(UIViewController *)callVC{
    if (phoneNum && ![phoneNum isEqualToString:@""]) {
        if (![[UIDevice currentDevice].model isEqualToString:@"iPhone"]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"该设备不支持通讯功能" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }else {
            NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phoneNum]];
            
            UIWebView *myCallWebview = [[UIWebView alloc] init];
            [callVC.view addSubview:myCallWebview];
            [myCallWebview loadRequest:[NSURLRequest requestWithURL:phoneUrl]];
        }
    }
}

+ (UIImage *)createImageWithColor:(UIColor *)color{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return theImage;
}

//判断手机号
+ (BOOL) validateMobile:(NSString *)mobile{
    if (mobile.length==0) {
        return NO;
    }
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(14[0-9])|(17[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}
//银行卡号验证正责
//+ (BOOL) validateBankCard:(NSString*) cardNo{
//    if (cardNo.length==0) {
////        [[TKAlertCenter defaultCenter] postAlertWithMessage:@""];
//        return NO;
//    }
//    int oddsum = 0;     //奇数求和
//    int evensum = 0;    //偶数求和
//    int allsum = 0;
//    int cardNoLength = (int)[cardNo length];
//    int lastNum = [[cardNo substringFromIndex:cardNoLength-1] intValue];
//    
//    cardNo = [cardNo substringToIndex:cardNoLength - 1];
//    for (int i = cardNoLength -1 ; i>=1;i--) {
//        NSString *tmpString = [cardNo substringWithRange:NSMakeRange(i-1, 1)];
//        int tmpVal = [tmpString intValue];
//        if (cardNoLength % 2 ==1 ) {
//            if((i % 2) == 0){
//                tmpVal *= 2;
//                if(tmpVal>=10)
//                    tmpVal -= 9;
//                evensum += tmpVal;
//            }else{
//                oddsum += tmpVal;
//            }
//        }else{
//            if((i % 2) == 1){
//                tmpVal *= 2;
//                if(tmpVal>=10)
//                    tmpVal -= 9;
//                evensum += tmpVal;
//            }else{
//                oddsum += tmpVal;
//            }
//        }
//    }
//    
//    allsum = oddsum + evensum;
//    allsum += lastNum;
//    if((allsum % 10) == 0)
//        return YES;
//    else
//        return NO;
//}
+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"星期日", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}
+(int)daysFromStartDate:(NSDate*)sDate toEndDate:(NSDate*)eDate{
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //用[NSDate date]可以获取系统当前时间
    NSString *startDateStr = [dateFormatter stringFromDate:sDate];
    NSString *endDateStr = [dateFormatter stringFromDate:eDate];
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *startDate = [dateFormatter dateFromString:[startDateStr componentsSeparatedByString:@" "][0]];
    NSDate *endDate = [dateFormatter dateFromString:[endDateStr componentsSeparatedByString:@" "][0]];
    NSTimeInterval secs=[endDate timeIntervalSinceDate:startDate];
    return (int)(secs/(3600*24));
}
+(BOOL)isTheSameDayBetween:(NSDate*)sDate andDate:(NSDate*)eDate{
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    //用[NSDate date]可以获取系统当前时间
    NSString *startDateStr = [dateFormatter stringFromDate:sDate];
    NSString *endDateStr = [dateFormatter stringFromDate:eDate];
    
    return [startDateStr isEqualToString:endDateStr];
}

//邮箱判断
+(BOOL)checkEmail:(NSString *)str{
//    if (str.length==0) {
//        [[TKAlertCenter defaultCenter] postAlertWithMessage:@"邮箱不能为空,请重新设置"];
//
//        return NO;
//    }
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    if ([emailTest evaluateWithObject:str]) {
        return YES;
    }
    else
    {
        if (str.length == 0) {
            return YES;

        }else{
            [[TKAlertCenter defaultCenter] postAlertWithMessage:@"邮箱格式错误,请重新设置"];
            return NO;

        }
        return YES;
    }
    
}
//输入密码判断
+(BOOL)checkPassWord:(NSString *)str{
    if (str.length > 18) {
        [[TKAlertCenter defaultCenter] postAlertWithMessage:[NSString stringWithFormat:@"请输入6-18位的登录密码"]];
        return NO;
    }
    else if (str.length < 6)
    {
        if (str.length == 0) {
            [[TKAlertCenter defaultCenter] postAlertWithMessage:[NSString stringWithFormat:@"密码不能为空,请重新设置"]];
            return NO;
        }else{
            [[TKAlertCenter defaultCenter] postAlertWithMessage:[NSString stringWithFormat:@"请输入6-18位的登录密码"]];
            return NO;
        }
    }
    //6-18位数字和字母组成
    NSString *regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,18}$";
    NSString *zmregex = @"^[A-Za-z]+$";
    NSString *industrialRegex = @"^[0-9]*$";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", industrialRegex];
    NSPredicate *   pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    NSPredicate *   zmpred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", zmregex];
    if ([pred evaluateWithObject:str]||[zmpred evaluateWithObject:str]||[emailTest evaluateWithObject:str]) {
        return YES ;
    }
    else
    {
        [[TKAlertCenter defaultCenter] postAlertWithMessage:[NSString stringWithFormat:@"密码设置错误,请重新设置"]];
        return NO;
    }
    
}
//手机号码验证
+ (BOOL)checkTel:(NSString *)str{
    if ([str length] == 0) {
        
        [[TKAlertCenter defaultCenter] postAlertWithMessage:@"手机号码不能为空"];
        return NO;
        
    };
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *regex = @"^((13[0-9])|(14[0-9])|(17[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
//    NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
    
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch) {
        [[TKAlertCenter defaultCenter] postAlertWithMessage:@"请输入正确的手机号码"];
        
        return NO;
        
    }
    return YES;
}
//身份证号
+ (BOOL) validateIdentityCard: (NSString *)identityCard{

    if (identityCard.length == 0) {
        return NO;
    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    BOOL isMatch =  [identityCardPredicate evaluateWithObject:identityCard];
    return isMatch;
}
/**
 *  银行卡号验证
 *
 *  @param cardNo 银行卡号
 *
 *  @return 返回是否为银行卡号
 */
+ (BOOL) validateBankCard:(NSString*) cardNo{
    if (cardNo.length<16 || cardNo.length>19) {
        return NO;
    }
    int oddsum = 0;     //奇数求和
    int evensum = 0;    //偶数求和
    int allsum = 0;
    int cardNoLength = (int)[cardNo length];
    int lastNum = [[cardNo substringFromIndex:cardNoLength-1] intValue];
    
    cardNo = [cardNo substringToIndex:cardNoLength - 1];
    for (int i = cardNoLength -1 ; i>=1;i--) {
        NSString *tmpString = [cardNo substringWithRange:NSMakeRange(i-1, 1)];
        int tmpVal = [tmpString intValue];
        if (cardNoLength % 2 ==1 ) {
            if((i % 2) == 0){
                tmpVal *= 2;
                if(tmpVal>=10)
                    tmpVal -= 9;
                evensum += tmpVal;
            }else{
                oddsum += tmpVal;
            }
        }else{
            if((i % 2) == 1){
                tmpVal *= 2;
                if(tmpVal>=10)
                    tmpVal -= 9;
                evensum += tmpVal;
            }else{
                oddsum += tmpVal;
            }
        }
    }
    
    allsum = oddsum + evensum;
    allsum += lastNum;
    if((allsum % 10) == 0)
        return YES;
    else
        return NO;
}

+ (NSString *)createUUID{
    
    CFUUIDRef uuid_ref = CFUUIDCreate(NULL);
    CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);
    
    CFRelease(uuid_ref);
    NSString *uuid = [NSString stringWithString:(__bridge NSString*)uuid_string_ref];
    
    CFRelease(uuid_string_ref);
    return uuid;
    
}
- (BOOL)validateMobile:(NSString *)mobileNum{
    /**
     
     * 手机号码
     
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     
     * 联通：130,131,132,152,155,156,185,186
     
     * 电信：133,1349,153,180,189
     
     */
    NSString * MOBILE =@"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
    /**
     
     10         * 中国移动：China Mobile
     
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     
     12         */
    NSString *CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    /**
     
     15         * 中国联通：China Unicom
     
     16         * 130,131,132,152,155,156,185,186
     
     17         */
    NSString *CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    
    /**
     
     20         * 中国电信：China Telecom
     
     21         * 133,1349,153,180,189
     
     22         */
    
    NSString *CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    
    /**
     
     25         * 大陆地区固话及小灵通
     
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     
     27         * 号码：七位或八位
     
     28         */
    
    // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CT];
    if(([regextestmobile evaluateWithObject:mobileNum] == YES)
       ||([regextestcm evaluateWithObject:mobileNum] == YES)
       ||([regextestcu evaluateWithObject:mobileNum] == YES)
       ||([regextestct evaluateWithObject:mobileNum] == YES)){
        return YES;
    }
    else{
        return NO;
    }
}

+ (NSString *)encryptForMobile:(NSString *)phoneNumber
{
    if (phoneNumber.length == 11)
    {
       return [phoneNumber stringByReplacingCharactersInRange:NSMakeRange(4, 4) withString:@"****"];
    }
    return phoneNumber;
}


+ (NSString *)stringByDateStr:(NSString *)dateString withFormatter:(NSString *)formatter
{
    if (dateString.length != 19)
    {
        return dateString;
    }else
    {
        NSString *result;
        NSDateFormatter *formatt = [[NSDateFormatter alloc]init];
        [formatt setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *date = [formatt dateFromString:dateString];
        [formatt setDateFormat:formatter];
        result = [formatt stringFromDate:date];
        return  result;
    }
}
/**
 *  计算剩余天数
 *
 *  @param dateString 未来的日期
 *
 *  @return 返回距离未来日期的天数
 */
+ (NSString*)calculateRemainingDays:(NSString*)dateString{
    NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
    [calendar setFirstWeekday:2];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *fromDate;
    NSDate *toDate;
    [calendar rangeOfUnit:NSDayCalendarUnit startDate:&toDate interval:NULL forDate:[dateFormatter dateFromString:dateString]];
    [calendar rangeOfUnit:NSDayCalendarUnit startDate:&fromDate interval:NULL forDate:[NSDate date]];
    NSDateComponents *dayComponents =[calendar components:NSDayCalendarUnit fromDate:fromDate toDate:toDate options:0];
    if (dayComponents.hour>0||dayComponents.minute>0) {
        return [NSString stringWithFormat:@"%ld",(long)dayComponents.day+1];
    }
    return [NSString stringWithFormat:@"%ld",(long)dayComponents.day];
}

//时间转换
+ (NSDate *)getDateWithDateString:(NSString *)DateStr
{
    NSDateFormatter *inputFormatter= [[NSDateFormatter alloc] init];
    [inputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss "];
    NSDate *aDate = [inputFormatter dateFromString:DateStr];
    return aDate;
}

//时间差
+ (NSDateComponents *)getTimeDifferenceWithOldDate:(NSDate *)oldDate newDate:(NSDate *)newDate
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *timeNum = [calendar components:unitFlags fromDate:oldDate toDate:newDate options:0];//计算时间差
    return timeNum;
}
/**
 *  时间戳转日期
 *
 *  @param timestamp 时间戳
 *
 *  @return 日期
 */
+ (NSString*)timestampChangeDateTime:(NSString*)timestamp formatter:(NSString*)formatter{
    NSString *timestampStr = timestamp;
    if (![timestamp isKindOfClass:[NSString class]]) {
        timestampStr = [NSString stringWithFormat:@"%@",timestamp];
    }
    NSTimeInterval dateTime = [timestampStr doubleValue];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:formatter];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:dateTime/1000.0f];
    return  [dateFormatter stringFromDate:date];
}
/**
 *  字节的转换
 *
 *  @param byteString 字节b
 *
 *  @return 转换成GB、MB、KB
 */
+ (NSString*)byteConversionGBMBKB:(NSString*)fileSize{
    const int GB = 1024*1024*1024;//定义GB的计算常量
    const int MB = 1024*1024;
    const int KB = 1024;
    NSInteger byteInterger = fileSize.integerValue;
    NSString *fileSizeStr = @"";
    if (byteInterger/GB>=1) {
        fileSizeStr = [NSString stringWithFormat:@"%.2fGB",fileSize.doubleValue/(float)GB];
        
    }else if (byteInterger/MB>=1){
        fileSizeStr = [NSString stringWithFormat:@"%.2fMB",fileSize.doubleValue/(float)MB];
    }else if (byteInterger/KB>=1){
        fileSizeStr = [NSString stringWithFormat:@"%.2fKB",fileSize.doubleValue/(float)KB];
    }else{
        fileSizeStr = [NSString stringWithFormat:@"%ldB",(long)fileSize.integerValue];
    }
    return fileSizeStr;
}

+ (NSString *)getOrderStatusWithApprovalType:(NSString *)approvalType orderStatus:(NSString *)orderStatus
{
    if ([approvalType isEqualToString:@"1"] && [orderStatus isEqualToString:@"4"]) {
        return @"待支付";
    }
    if (!approvalType || [approvalType isEqualToString:@"0"] || [approvalType isEqual:[NSNull null]])
    {
        switch ([orderStatus integerValue])
        {
            case 0:
            {
                return @"待提交";
            }
                break;
            case 1:
            {
                return @"待审批";
            }
                break;
            case 2:
            {
                return @"审批中";
            }
                break;
            case 3:
            {
                return @"待生产部审批";
            }
                break;
            case 4:
            {
                return @"待支付";
            }
                break;
            case 5:
            {
                return @"待发货";
            }
                break;
            case 6:
            {
                return @"待收货";
            }
                break;
            case 7:
            {
                return @"已完成";
            }
                break;
            case 8: {
                return @"待财务部审批";
            }
                break;
                
            default:
                break;
        }

    }
    else
    {
        return @"已拒绝";
    }
        return nil;
}

+ (NSString *)getSaleApplyStatusWithApprovalStatus:(NSString *)approvalStatus approvalType:(NSString *)approvalType
{
    //0.待提交1待审核2.审核中 3策划部门4营销中心6完成
    if ([approvalType isEqualToString:@"0"])
    {
        //没有拒绝
        switch ([approvalStatus integerValue])
        {
            case 0:
            {
                return @"待提交";
            }
                break;
            case 1:
            {
                return @"待审批";
            }
                break;
            case 2:
            {
                return @"审批中";
            }
                break;
            case 3:
            {
                return @"审批中";
            }
                break;
            case 4:
            {
                return @"审批中";
            }
                break;
            case 6:
            {
                return @"已完成";
            }
                break;
            case 7:
            {
                return @"已查看";
            }
                 break;
            default:
                break;
        }
    }
    else
    {
        return @"已拒绝";
    }
        return nil;
}

+ (NSString *)getSaleCheckStatusWithApprovalStatus:(NSString *)approvalStatus approvalType:(NSString *)approvalType
{
    //审批状态（0.待核销1待审核2.审核中 3策划部门4财务部门5营销中心6完成）
    
    
    if ([approvalType isEqualToString:@"0"])
    {
        //没有拒绝
        switch ([approvalStatus integerValue])
        {
            case 0:
            {
                return @"待核销";
            }
                break;
            case 1:
            {
                return @"待审批";
            }
                break;
            case 2:
            {
                return @"审批中";
            }
                break;
            case 3:
            {
                return @"审批中";
            }
                break;
            case 4:
            {
                return @"审批中";
            }
                break;
            case 5:
            {
                return @"审批中";
            }
                break;
            case 6:
            {
                return @"已完成";
            }
                break;
            case 7:
            {
                return @"已查看";
            }
                break;
            default:
                break;
        }
    }
    else
    {
        return @"已拒绝";
    }
    return nil;
}

//促销目的（1推动渠道2提升认知3推动试用4提高使用量5推动忠诚度）
+ (NSString *)getActiviteGoalStrWithNumberStr:(NSString *)numberStr
{
    switch ([numberStr integerValue])
    {
        case 1:
            return @"推动渠道";
            break;
        case 2:
            return @"提升认知";
            break;
        case 3:
            return @"推动试用";
            break;
        case 4:
            return @"提高使用量";
            break;
        case 5:
            return @"推动忠诚度";
            break;
        default:
            break;
    }
    return @"";
}



@end
